<?php
namespace c\img;

/**
 * Description of screenshot
 *
 * @author YeFng
 */
class cut extends b
{
    /**
     * 截图
     * $f  文件地址
     * $w  宽
     * $h  高
     */
    function index_home()
    {
        \YF_f::initC('\c\auth\permission')->login();
        $p = $_POST;
        $src = $this->im($p['url']);
        $s_x = imagesx($src);
        $s_y = imagesy($src);

        //调整大小
        $w = intval($p['w']);
        $h = intval($p['h']);
        if ($w != $s_x or $h != $s_y) {
            $dst = imagecreatetruecolor($w, $h);
            imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $s_x, $s_y);
            $src = $dst;
            $s_x = $w;
            $s_y = $h;
        }
        //切
        $cw = intval($p['cw']);
        $ch = intval($p['ch']);
        $cl = intval($p['cl']);
        $ct = intval($p['ct']);

        $dst = imagecreatetruecolor($cw, $ch);
        imagecopyresampled($dst, $src, 0, 0, $cl, $ct, $cw, $ch, $cw, $ch);

        $path = 'shot/' . date('Ym/');
        $fileName = \YF_f::initC('\c\file\upload')->buildFile($path, uniqid() . '.'. $this->extName($p['url']));
        
        $this->imOut(FILE_DIR . $dir . $fileName, $dst);
        ajax_json(array('state'=>TRUE,'url'=>'?u=cimg\b&q='. \encrypt::q_ed('f='.$path . $fileName)) );
    }
}
